﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using ModuleDALCore;
using System.Data;
namespace DAL
{
    public class VATLIEUDAO:DALBase
    {

        public VATLIEUDAO()
        {
            this.OpenConnect();
        }
        private DataTable dt;
        private string _SpName;

        public string SpName
        {
            get { return "SPVATLIEU"; }
            set { _SpName = value; }
        }
        public DataTable GetListVL()
        {
            dt = new DataTable();
            try
            {
                dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new VATLIEU(), null), ConvertClassToArray.GetValues(new VATLIEU(), 0));
            }
            catch {  }
			return dt;
        }
		public DataTable FindThuocByCriteria(VATLIEU vl)
		{
			dt = new DataTable();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(vl, null), ConvertClassToArray.GetValues(vl, 6));
			}
			catch {  }
			return dt;
		}
		public List<VATLIEU> FindThuocByCriterias(VATLIEU vl)
		{
			dt = new DataTable();
			List<VATLIEU> dsvt = new List<VATLIEU>();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new VATLIEU(), null), ConvertClassToArray.GetValues(new VATLIEU(), 6));
				dsvt = (List<VATLIEU>) ConvertDatatableToList.ConvertTo<VATLIEU>(dt);
			}
			catch {  }
			return dsvt;
		}

		public DONVITINH GetDVTbyIDVL(VATLIEU vl)
		{
			dt = new DataTable();
			DONVITINH dvt = new DONVITINH();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(vl, null), ConvertClassToArray.GetValues(vl, 8));
				dvt = (DONVITINH)ConvertDatatableToList.ConvertToObject<DONVITINH>(dt);
			}
			catch {  }
			return dvt;
		}
		public List<NHOMHANG> GETNHOMTHEOLOAIVATLIEU(VATLIEU NH)
		{
			dt = new DataTable();
			List<NHOMHANG> bc = new List<NHOMHANG>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(NH, null), ConvertClassToArray.GetValues(NH, 7));
				bc = (List<NHOMHANG>)ConvertDatatableToList.ConvertTo<NHOMHANG>(dt);
				return bc;
			}
			catch { return null; }
		}
        public List<VATLIEU> GetListVLL(VATLIEU vl)
        {
            dt = new DataTable();
            List<VATLIEU> dsvt = new List<VATLIEU>();
            try
            {
                dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(vl, null), ConvertClassToArray.GetValues(vl, 0));
                dsvt = (List<VATLIEU>)ConvertDatatableToList.ConvertTo<VATLIEU>(dt);
            }
            catch {  }
            return dsvt;
        }
		public List<VATLIEU> GetListTHUOC()
		{
			dt = new DataTable();
			List<VATLIEU> dsvt = new List<VATLIEU>();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new VATLIEU(), null), ConvertClassToArray.GetValues(new VATLIEU(), 5));
				dsvt = (List<VATLIEU>)ConvertDatatableToList.ConvertTo<VATLIEU>(dt);
			}
			catch {  }
			return dsvt;
		}
        public String CreatenewId()
        {
            try
            {
                return "VL" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new VATLIEU(), null), ConvertClassToArray.GetValues(new VATLIEU(), 1));
            }
            catch { return null; }
        }
        public bool INSERT(VATLIEU vl)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(vl, null), ConvertClassToArray.GetValues(vl, 2)) == 1);

            }
            catch { return false; }
        }
        public bool UPDATE(VATLIEU vl)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(vl, null), ConvertClassToArray.GetValues(vl, 3)) == 1);

            }
			catch { return false; }
        }
        public bool DELETE(VATLIEU vl)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(vl, null), ConvertClassToArray.GetValues(vl, 4)) == 1);

            }
			catch { return false; }
        }
		public VATLIEU GetVLbyIDVL(VATLIEU vl)
		{
			DataTable dt = new DataTable();
			VATLIEU vlmoi = new VATLIEU();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(vl, null), ConvertClassToArray.GetValues(vl, 9));
				vlmoi = (VATLIEU)ConvertDatatableToList.ConvertToObject<VATLIEU>(dt);
			}
			catch { }
			return vlmoi;
		}
    }
}